
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module simpleparse.examples.py_ebnf</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="simpleparse.html"><font color="#ffffff">simpleparse</font></a>.<a href="simpleparse.examples.html"><font color="#ffffff">examples</font></a>.py_ebnf</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/mcfletch/pylive/simpleparse/examples/py_ebnf.py">/home/mcfletch/pylive/simpleparse/examples/py_ebnf.py</a></font></td></tr></table>
    <p><tt>This&nbsp;module&nbsp;defines&nbsp;a&nbsp;parser&nbsp;for&nbsp;the&nbsp;EBNF&nbsp;format&nbsp;used&nbsp;to&nbsp;define&nbsp;Python's&nbsp;grammar<br>
&nbsp;<br>
The&nbsp;grammar&nbsp;in&nbsp;the&nbsp;language&nbsp;reference&nbsp;(as&nbsp;seen&nbsp;in&nbsp;Python&nbsp;2.2.1)<br>
seems&nbsp;to&nbsp;be&nbsp;somewhat&nbsp;messed&nbsp;up.&nbsp;&nbsp;I've&nbsp;tried&nbsp;to&nbsp;fix&nbsp;the&nbsp;glaring<br>
errors&nbsp;(such&nbsp;as&nbsp;control&nbsp;codes&nbsp;included&nbsp;in&nbsp;the&nbsp;text&nbsp;version)&nbsp;and<br>
have&nbsp;saved&nbsp;this&nbsp;in&nbsp;the&nbsp;examples&nbsp;directory.<br>
&nbsp;<br>
This&nbsp;parser&nbsp;does&nbsp;parse&nbsp;the&nbsp;entire&nbsp;(fixed)&nbsp;grammar,&nbsp;with&nbsp;the<br>
exception&nbsp;of&nbsp;the&nbsp;&lt;XXX&gt;&nbsp;style&nbsp;comments&nbsp;which&nbsp;were&nbsp;used&nbsp;in&nbsp;a&nbsp;few<br>
places&nbsp;in&nbsp;the&nbsp;grammar&nbsp;to&nbsp;say&nbsp;"range&nbsp;of&nbsp;characters"<br>
&nbsp;<br>
What&nbsp;this&nbsp;doesn't&nbsp;do,&nbsp;is&nbsp;try&nbsp;to&nbsp;_use_&nbsp;the&nbsp;parsed&nbsp;grammar.&nbsp;&nbsp;The<br>
grammar&nbsp;is&nbsp;assuming&nbsp;a&nbsp;very&nbsp;different&nbsp;parser&nbsp;type&nbsp;than&nbsp;SimpleParse,<br>
for&nbsp;instance,&nbsp;it&nbsp;assumes&nbsp;that&nbsp;alternation&nbsp;(|)&nbsp;will&nbsp;use&nbsp;longest-of<br>
semantics,&nbsp;so&nbsp;that:<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:=&nbsp;blah<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;long_int&nbsp;:=&nbsp;int,&nbsp;[lL]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;all_ints&nbsp;:=&nbsp;int,&nbsp;long_int<br>
&nbsp;<br>
Would&nbsp;match&nbsp;long_int&nbsp;(because&nbsp;it's&nbsp;longest),&nbsp;rather&nbsp;than&nbsp;int,&nbsp;which<br>
is&nbsp;what&nbsp;the&nbsp;base&nbsp;SimpleParse&nbsp;FOGroup&nbsp;would&nbsp;do.&nbsp;&nbsp;You&nbsp;could&nbsp;fairly<br>
trivially&nbsp;make&nbsp;a&nbsp;processor&nbsp;similar&nbsp;to&nbsp;the&nbsp;simpleparsegrammar&nbsp;one<br>
to&nbsp;make&nbsp;objectgenerator&nbsp;objects&nbsp;from&nbsp;the&nbsp;parsed&nbsp;format,&nbsp;but&nbsp;the<br>
resulting&nbsp;parser&nbsp;just&nbsp;wouldn't&nbsp;work&nbsp;because&nbsp;of&nbsp;the&nbsp;differences&nbsp;in<br>
parser&nbsp;capability.<br>
&nbsp;<br>
Basically,&nbsp;we'll&nbsp;want&nbsp;to&nbsp;have&nbsp;a&nbsp;new&nbsp;back-end&nbsp;before&nbsp;continuing&nbsp;on<br>
with&nbsp;this&nbsp;demo.<br>
&nbsp;<br>
The&nbsp;grammar&nbsp;being&nbsp;parsed&nbsp;(and&nbsp;included)&nbsp;is&nbsp;part&nbsp;of&nbsp;Python,&nbsp;so<br>
here's&nbsp;the&nbsp;copyright&nbsp;notice:<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Python&nbsp;is&nbsp;Copyright&nbsp;(c)&nbsp;2001,&nbsp;2002&nbsp;Python&nbsp;Software&nbsp;Foundation.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;All&nbsp;Rights&nbsp;Reserved.<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Copyright&nbsp;(c)&nbsp;2000&nbsp;BeOpen.com.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;All&nbsp;Rights&nbsp;Reserved.<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Copyright&nbsp;(c)&nbsp;1995-2001&nbsp;Corporation&nbsp;for&nbsp;National&nbsp;Research&nbsp;Initiatives.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;All&nbsp;Rights&nbsp;Reserved.<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Copyright&nbsp;(c)&nbsp;1991-1995&nbsp;Stichting&nbsp;Mathematisch&nbsp;Centrum,&nbsp;Amsterdam.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;All&nbsp;Rights&nbsp;Reserved.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
You&nbsp;should&nbsp;have&nbsp;a&nbsp;full&nbsp;copy&nbsp;of&nbsp;the&nbsp;Python&nbsp;license&nbsp;in&nbsp;your&nbsp;Python<br>
distribution.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="simpleparse.common.strings.html">simpleparse.common.strings</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>declaration</strong> = "<font color="#c040c0">\n\n</font>declarationset      :=  declaration+<font color="#c040c0">\n</font>declarati...              :=  string, ts, '...', ts, string<font color="#c040c0">\n\n</font>"<br>
<strong>parser</strong> = &lt;simpleparse.parser.Parser instance&gt;</td></tr></table>
</body></html>